package producers;

import codeComposition.*;
import util.*;
import java.util.*;
public class ItemProducer implements Producer{

	String name;
	ArrayList<String> fields;
	public ItemProducer(String name, String[] fields){
		this.name = name;
		this.fields = Translator.stringsToList(fields);
	}
	public void setFields(String[] fields){
		this.fields = Translator.stringsToList(fields);
	}
	public ItemProducer(String name, ArrayList<String> fields){
		this.name = name;
		this.fields = fields;
	}
	public void setFields(ArrayList<String> fields){
		this.fields = fields;
	}
	
	public String produce(){
		ModelElement itemModel = new ModelElement("item");
		String[] im = {"Item","Field"};
		ImportElement ime = new ImportElement("scrapy.item",im);
		itemModel.addImport(ime);
		ClassElement itemClass = new ClassElement(name+"Item", "Item");
		for(String s: fields){
			ConstructElement ce = new ConstructElement("Field", s,1);
			itemClass.add(ce);
		}
		ConstructElement ce = new ConstructElement("Field", "url",1);
		itemClass.add(ce);
		itemModel.addClass(itemClass);
		return itemModel.toString();
	}
}
